<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<html>
<head>
    <%
        String path = request.getContextPath();
        String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    %>
    <base href="<%=basePath%>">
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <title>Title</title>
    <script src="js/jquery-1.8.0.js"></script>
    <link rel="stylesheet" type="text/css" href="css/maintable.css" ></link>
    <script>
        $(function(){
            $("#ch_checkall,#top_ch_checkall").click(function(){
                if(this.checked){
                    $("input[name=ck_id]").attr("checked","checked");
                }else{
                    $("input[name=ck_id]").removeAttr("checked");
                }
            });

            $("table tr").mouseover(function(){
                $(this).css("background","#D3EAEF");
                $(this).siblings().css("background","white");
            });
        });

        $(function () {
            $("#but1").click(function () {
                var a= $("#bigCateId").val();
                var b= $("#smallCateId").val();
                var c= $("#goods").val();
                window.location.href="GoodsServlet?flag=manage&pageIndex=1&bigC="+a+"&smallC="+b+"&goods="+c;
            });
            $("#but2").click(function () {
                var a= $("#bigCateId").val();
                var b= $("#smallCateId").val();
                var c= $("#goods").val();
                window.location.href="GoodsServlet?flag=manage&bigC="+a+"&smallC="+b+"&goods="+c+"&pageIndex="+${page.pageIndex-1};
            });
            $("#but3").click(function () {
                var a= $("#bigCateId").val();
                var b= $("#smallCateId").val();
                var c= $("#goods").val();
                window.location.href="GoodsServlet?flag=manage&bigC="+a+"&smallC="+b+"&goods="+c+"&pageIndex="+${page.pageIndex+1};
            });
            $("#but4").click(function () {
                var a= $("#bigCateId").val();
                var b= $("#smallCateId").val();
                var c= $("#goods").val();
                window.location.href="GoodsServlet?flag=manage&bigC="+a+"&smallC="+b+"&goods="+c+"&pageIndex="+${page.pageCount };
            });
        });
        $(function () {
            $("#duoxuan").click(function () {
                var xuanze=document.getElementsByName("ck_id");
                var st=document.getElementsByName("st");
                var idlist="";
                for(var i=0;i<xuanze.length;i++){
                    if(xuanze[i].checked==true){
                        idlist=idlist+xuanze[i].id+" ";
                    }
                }
                window.location.href="GoodsServlet?flag=duoshan&id="+idlist+"&pageIndex="+${page.pageIndex};
            });
        });
        $(function () {
           $("#subx").click(function () {
               var a= $("#bigCateId").val();
               var b= $("#smallCateId").val();
               var c= $("#goods").val();
               window.location.href="GoodsServlet?flag=manage&bigC="+a+"&smallC="+b+"&goods="+c;
           }) ;
        });

        $(function(){
            $("#bigCateId").change(function(){
                $("#smallCateId").empty();
                    $("#smallCateId").append("<option value=''>==小分类==</option>");
                    var s=this.value;
                    $.ajax({
                        url: "GoodsServlet",
                        type: "post",
                        dataType:"json",
                        data: {
                            flag: "smallc", parentId: s
                        },
                        success: function (data) {
                            $.each(data, function () {
                                var str = "<option value='" +this.id+ "' <c:if test='${bigCate="+this.id+"}'>selected</c:if>>" + this.cateName + "</option>";
                                $("#smallCateId").append(str);
                            });
                        }
                    });
            });
        });
    </script>

</head>
<body>
<div class ="div_title">
    <div class="div_titlename"> <img src="images/san_jiao.gif" ><span>商品基本信息列表</span></div>
    <div class="div_titleoper">
        <input type="checkbox" id="top_ch_checkall"/> 全选
        <a href="goods/goods-add.jsp"><img src="images/add.gif"/>添加 </a>
        <a onclick="return confirm('确定要删除吗')" id="duoxuan"><img src="images/del.gif"/>删除</a> </div>
</div>

<form action="xxx"  name="form1">
    大分类：
    <select name="bigC" id="bigCateId">
        <option value="">=大分类=</option>
        <c:forEach var="c" items="${blist}">
        <option value="${c.parentId}" <c:if test="${bigCate}==${c.parentId}">selected</c:if> >${c.cateName}</option>
        </c:forEach>
    </select>
    小分类：
    <select name="smallC" id="smallCateId">
        <option value="">=小分类=</option>
    </select>
    商品名称：<input name="goods" id="goods" value="${goods}">
    <input type="button" id="subx" value="查询">
    <table class="main_table" >
        <tr>
            <th><input type="checkbox" id="ch_checkall" /></th>	<th>名称</th> 	<th>单位</th>	<th>单价</th>  <th>大分类</th> 	<th>小分类</th>	<th>操作</th>
        </tr>
        <c:forEach var="c" items="${goodslist}">
            <tr>
                <td>
                    <input type="checkbox" name="ck_id" id="${c.id}" />
                </td>
                <td>${c.goodsName}</td>
                <td name="st">${c.unit}</td>
                <td> <a >${c.price}</a> </td>
                <td> <a >${c.bigC()}</a> </td>
                <td> <a >${c.smallC()}</a> </td>
                <td>
                    <a href="GoodsServlet?flag=srea&id=${c.id}&pageIndex=${page.pageIndex}">查看</a> |
                    <a href="GoodsServlet?flag=update&id=${c.id}&pageIndex=${page.pageIndex}">修改</a> |
                    <a href="GoodsServlet?flag=delete&id=${c.id}&pageIndex=${page.pageIndex}" onclick="return confirm('确定要删除吗')">删除</a>
                </td>
            </tr>
        </c:forEach>
    </table>
</form>

<div class="div_page" >
    <div class="div_page_left">
        共有 <label>${page.rowCount }</label> 条记录，
        当前第 <label>${page.pageIndex}</label> 页，
        共 <label>${page.pageCount }</label> 页
    </div>
    <div class="div_page_right" >
        <c:choose>
            <c:when test="${page.hasPre }">
                <button id="but1">首页</button>
                <button id="but2"> 上一页</button>
            </c:when>
            <c:otherwise>
                首页
                上一页
            </c:otherwise>
        </c:choose>

        <c:choose>
            <c:when test="${page.hasNext }">
                <button id="but3">下一页 </button>
                <button id="but4">尾页</button>
            </c:when>
            <c:otherwise>
                下一页
                尾页
            </c:otherwise>
        </c:choose>
        <button id="but5">转到</button>
        <input type="text" name="pageIndex" id="pageIndex" value="1" /> 页

    </div>

</div>
</body>
</html>
